stage.set_background("schoolentrance")
stage.wait(2)
stage.create_grid_overlay(50, "blue")
stage.set_background_color("azure")
emma = codesters.Sprite("person1")
emma.set_size(0.5)
michael = codesters.Sprite("person2")
michael.set_size(0.5)
emma_x = random.randint(-230,230)
emma_y = random.randint(-230,230)
emma.go_to(emma_x, emma_y)
michael_x = random.randint(-230,230)
michael_y = random.randint(-230,230)
michael.go_to(michael_x, michael_y)
delta_x = emma_x - michael_x
delta_y = emma_y - michael_y
distance = math.sqrt((delta_x**2) + (delta_y**2))
if distance <= 200:
# add your code here
emma.say("I am a sprite.")
t = codesters.Teacher()
loads = t.find_text('.load_image')
try:
params = t.get_parameters_for_function('load_image')
tval1 = params[0][0]
tval1a = tval1.strip('\"')
except:
tval1 = "DNE"
tval1a = "DNE"
try:
sprites = t.get_parameters_for_function('Sprite')
tval2 = sprites[0][0]
tval2a =tval2.strip('\"')
except:
tval2 = "DNE"
tval2a = "DNE"
try:
tval3 = loads[0][1]
except:
tval3 = "DNE"
try:
indent = loads[0][0]
tval4 = t.get_indent_at_line(indent)
except:
tval4 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == '"person1_masked"', "Great Job!")
t1.add_failure(tval1 == 'DNE', "Did you add a Change Image tool?")
t1.add_failure(tval2 != '"person1"' and tval2a not in tval1a, "Your masked sprite doesn't match your original sprite! Change the string in emma.load_image() to match the original image.")
t1.add_creative(tval2 != '"person1"' and tval2a in tval1a, "Your masked sprite matches your sprite: good work!")
t2 = TestObjective()
t2.add_success('emma' in tval3, "Great Job!!")
t2.add_failure('emma' not in tval3, "Did you change the name in front of .load_image() to emma?")
t2.add_failure(tval3 == "DNE", "Did you add a Change Image tool?")
t3 = TestObjective()
t3.add_success(tval4 == 4, "Great job!")
t3.add_failure(tval4 == 0, "Did you indent the .load_image() 4 spaces inside the if statement?")
t3.add_failure(tval4 == "DNE", "Did you add a Change Image tool in the if statement?")
t3.add_failure(tval4 > 4, "You indented .load_iamge() too far.")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)